﻿using System.Data;
using ChurchDiary.DAL.Contract;
using System.Data.SqlClient;
using System;

namespace ChurchDiary.DAL.Methods
{
    public class DAL_Tools : ITools
    {
        string connectionString = "data source=IDCSQL3.znetlive.com,1234;initial catalog=ChurchDB;persist security info=True;user id=justinsam;password=Ju$t!ns@m123;";
        public DataTable GetAllTables()
        {
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                connection.Open();
                DataTable schema = connection.GetSchema("Tables");
                return schema;
            }
        }

        public DataTable GetTableInfo(string tableName,string procedureName)
        {
            DataTable dt = new DataTable();
            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                try
                {
                    using (SqlCommand cmd = new SqlCommand(procedureName, conn))
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.Add(new SqlParameter("@TableName", tableName));
                        using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                        {
                            da.Fill(dt);
                        }
                    }
                }
                catch (Exception ex)
                {
                }
            }
            return dt;
        }
    }
}
